
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Mr Bao
 */
public class AddNewAlbumForm extends Form implements CommandListener {

    private TextField txtAlbumName;
    private HomeScreen homeScreen;
    private Command cmdNew;
    private Command cmdBack = new Command("Back", Command.BACK, 2);

    public AddNewAlbumForm(HomeScreen homeScreen) {
        super("UpAnh");
        this.homeScreen = homeScreen;
        txtAlbumName = new TextField("Name", null, 50, TextField.ANY);
        append(txtAlbumName);
        cmdNew = new Command("Add New", Command.OK, 2);
        addCommand(cmdNew);
        addCommand(cmdBack);
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdNew) {
            if (CheckValid()) {
                Common.Client.CreateAlbum(txtAlbumName.getString());
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
                homeScreen.DisplayAlbumForm();
            }
        }else if (c==cmdBack){
            homeScreen.DisplayAlbumFormBack();
        }
    }

    private boolean CheckValid() {
        if (txtAlbumName.getString().trim().equals("")) {
            return false;
        }
        return true;
    }
}
